package com.dq.demo.ui.activity;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Window;

import com.dq.demo.manager.ActManager;
import com.dq.demo.util.EdittorUtil;
import com.dq.demo.util.StatusBarUtil;

/**
 * @author Administrator
 * @particulars
 * @time 2019\6\18 0018 10:18
 * @class describe
 */
public abstract class BaseActivity extends Activity {

    public String TAG = getClass().getSimpleName();

    public String[] permission = new String[]{
            Manifest.permission.CAMERA,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE};
    public int height;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActManager.getAppManager().addActivity(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
        setStatusBar();
    }

    public abstract void initView();
    public abstract void initData();

    /**
     * Activity跳转
     *
     * @param startAct
     * @param endAct
     * @return
     */
    public void startAct(Activity startAct, Activity endAct) {
        Intent intent = new Intent(startAct, endAct.getClass());
        startActivity(intent);
    }

    protected void setStatusBar() {
        height = StatusBarUtil.getStatusBarHeight(this);
        //当FitsSystemWindows设置 true 时，会在屏幕最上方预留出状态栏高度的 padding
        StatusBarUtil.setRootViewFitsSystemWindows(this, true);
        //设置状态栏透明
        StatusBarUtil.setTranslucentStatus(this);
    }

    /**
     * 设置状态栏字体颜色
     *
     * @param colors 颜色值
     */
    public void setStatusBarColor(int colors) {
        if (!StatusBarUtil.setStatusBarDarkTheme(this, true)) {
            StatusBarUtil.setStatusBarColor(this, colors);
        }
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config = res.getConfiguration();
        config.fontScale = 1;
        res.updateConfiguration(config, res.getDisplayMetrics());
        return res;
    }

    @Override
    protected void onPause() {
        super.onPause();
        EdittorUtil.hideInput(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActManager.getAppManager().finishActivity(this);
    }
}